/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.idei.filetree;

import java.awt.Component;
import java.io.File;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;

/**
 *
 * @author Emilio
 */
public class FileTreeRenderer extends DefaultTreeCellRenderer {
	private static final long serialVersionUID = 1l;
	private File file;

	@Override
	public Component getTreeCellRendererComponent(JTree tree,
			Object value, boolean sel, boolean expanded, boolean leaf, int row,
			boolean hasFocus) {
		try {
			file = new File(((DefaultMutableTreeNode) value).getUserObject().toString());
		} catch (Throwable th) {
			file = null;
		}
		return super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
	}
	
	@Override
	public String getText() {
		if (file == null) {
			return null;
		}
		return file.getName();
	}
}